package com.apes.autoparts.supplier.jikugroup;

import com.apes.framework.jpa.repository.CustomRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;

/**
 * Created by lishikun on 2021/3/15 14:31
 */
public interface JiKuGroupRepository extends CustomRepository<JiKuGroup, String>{

    @Query(value = "SELECT T.* FROM ji_ku_group T where T.parts_id in (?1) and T.supplier_platform_item_id = ?2",nativeQuery = true)
    List<JiKuGroup> findByIdsAndSupplierPlatformItem(@Param("ids") List<String> ids, @Param("supplierPlatformItemId") String supplierPlatformItemId);

    @Query(value = "select T.* FROM ji_ku_group T where T.supplier_platform_item_id = :supplierPlatformItemId and t.last_updated_stamp  > sysdate - (:hours / 24)",nativeQuery = true)
    List<Map> findBySupplierPlatformItemAndNotUpdate(@Param("supplierPlatformItemId") String supplierPlatformItemId, long hours);

    @Modifying
    @Query(value = "DELETE FROM ji_ku_group T where T.supplier_platform_item_id = :supplierPlatformItemId and t.last_updated_stamp  > sysdate - (:hours / 24)",nativeQuery = true)
    int deleteBySupplierPlatformItemAndNotUpdate(@Param("supplierPlatformItemId") String supplierPlatformItemId, long hours);
}
